package edu.zut.cs.software.perfect.student.web.spring.controller;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;

import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.student.domain.Classes;
import edu.zut.cs.software.perfect.student.service.ClassesManager;

/**
 * @ClassName ClassesController
 * @Description TODO
 * @Author jihao
 * @Date 2020年5月30日 上午12:25:02
 * @Version 1.0
 */

@RestController
@RequestMapping("/classes/class")
public class ClassesController extends GenericController<Classes, Long, ClassesManager>{

	ClassesManager classesManager;

	@RequestMapping(method = RequestMethod.GET, value = "/index.html")
	/*public String index() {
		String result = "/classes/index";
		return result;
	}*/
	
	public String getClassesAll() {
		return JSON.toJSONString(classesManager.findAll());
	}
	
	@Autowired
	public void setClassesManager(ClassesManager classesManager) {
		this.classesManager = classesManager;
		this.manager = this.classesManager;
	}
	
	@ResponseBody
    @GetMapping(value = "findall", produces = "application/json;charset=utf-8")
	public String findAllStudent() {
		List<Classes> classesList = this.manager.findAll();
        PageInfo pageInfo = new PageInfo(classesList);
        return JSON.toJSONString(pageInfo);
	}
	
	@GetMapping("/findbyid/{id}")
	public String findById(@PathVariable("id") Long id) {
		Optional<Classes> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	
//	@DeleteMapping("/deletebyid/{id}")
	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {
//		Optional<CourseInformation> courseInformation = this.manager.findByCourseId(id);
		Boolean result = this.manager.deleteClassesId(id);
		return result;
	}
}
